<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/5/24.
 */

namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Http\Request\System\LoginRequest;
use App\Service\LoginService;
use App\Utils\ResultsVo;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    private $loginService;

    public function __construct(LoginService $loginService)
    {
        parent::__construct();
        $this->loginService = $loginService;
    }

    public function login(LoginRequest $request): \Illuminate\Http\JsonResponse
    {
        $data = $this->loginService->login($request->only(['username', 'password', 'code']));

        return ResultsVo::success($data);
    }

    public function logout(): \Illuminate\Http\JsonResponse
    {
        Auth::guard('system')->logout();

        return ResultsVo::success();
    }
}
